import 'package:ymt/db/user_database_provider.dart';
import 'package:ymt/model/product/detail.dart';

class Product {
    int grandparent_id;
    int id;
    String main_picture;
    String main_picture_big;
    String name;
    int parent_id;
    ProductDetail detail;
    /// 以下数据库部分
    int retail_rate;
    int visible;
    int company_id;
    int product_category_id;

    Product({this.grandparent_id, this.id, this.main_picture, this.main_picture_big, this.name, this.parent_id});

    factory Product.fromJson(Map<String, dynamic> json) {
        return Product(
            grandparent_id: json['grandparent_id'],
            id: json['id'],
            main_picture: json['main_picture'],
            main_picture_big: json['main_picture_big'],
            name: json['name'],
            parent_id: json['parent_id'],
        );
    }

    Product.fromMap(Map<String, dynamic> map) {
        id = map[columnProductId];
        name = map[columnName];
        visible = map[columnVisible];
        main_picture = map[columnThumbPicture];
        main_picture_big = map[columnMainPicture];
        retail_rate = map[columnRetailRate];
        company_id = map[columnCompanyId];
        product_category_id = map[columnCategoryId];
    }

    Map<String, dynamic> toJson() {
        final Map<String, dynamic> data = new Map<String, dynamic>();
        data['grandparent_id'] = this.grandparent_id;
        data['id'] = this.id;
        data['main_picture'] = this.main_picture;
        data['main_picture_big'] = this.main_picture_big;
        data['name'] = this.name;
        data['parent_id'] = this.parent_id;
        return data;
    }
}